/****************************************************************************
*Tablas de traduccion utilizadas por el traductor                           *
*Author     :   Simon Emmanuel Gutierrez Brida                              *
*Version    :   0.3.1                                                       *
*Fecha      :   Octubre/2011                                                *
*----------------------------------------------------                       *
*Ofrece tablas de traduccion (PseudoAssembler -> Assembler)                 *
*Ofrece codigo auxiliar para completar el codigo                            *
*Ofrece cuales son las version de assembler soportadas                      *
*nota: cada version de assembler tendra su tabla de traduccion y su         *
*codigo auxiliar especifico                                                 *
*****************************************************************************/


#ifndef TABLASTRAD_H
#define TABLASTRAD_H

/**
 * Tabla que contiene los nombres de las versiones de assembler soportadas por este compilador
 */
static const char * versionNames[2] = {
    "PSEUDO",
    "GNUX86-AT&T"
};

/**
 * Tabla completamente sin ningun tipo de sentido, el sentido comun no se tuvo en cuenta cuando se creo esta tabla
 */
static const int versionIndexes[2] = {
    0,
    1
};

/**
 * Tabla que contiene los distintos intros para cada lenguaje resultado que soporta el compilador
 */
static const char * introAuxiliarCode[2] = {
    "INTROPSEUDO\n",
    "   .text\n.globl _%1$s\n_%1$s:\n   pushl %%ebp\n   movl %%esp, %%ebp\n   subl $%2$d, %%esp\n"
};

/**
 * Tabla que contiene los distintos outros para cada lenguaje resultado que soporta el compilador
 */
static const char * outroAuxiliarCode[2] = {
    "OUTROPSEUDO\n",
    ""
};

/**
 * Tabla de traduccion, que contiene la traduccion de cada comando para cada version assembler soportada por el compilador
 * se debe tener precausion con el manejo de indices cuando un comando puede tener varias traducciones posibles
 */
static const char * tablaTrad[2][32] = {
    {
        "LOAD_CONST %s %s\n",       //0
        "LOAD_MEM %s %s\n",         //1
        "STORE_CONST %s %s\n",      //2
        "STORE_MEM %s %s\n",        //3
        "COM_MINUS %s %s\n",        //4
        "COM_ADD %s %s %s\n",       //5
        "COM_SUB %s %s %s\n",       //6
        "COM_MULT %s %s %s\n",      //7
        "COM_DIV %s %s %s\n",       //8
        "COM_MOD %s %s %s\n",       //9 
        "COM_GT %s %s %s\n",        //10
        "COM_LT %s %s %s\n",        //11
        "COM_EQ %s %s %s\n",        //12
        "COM_AND %s %s %s\n",       //13
        "COM_OR %s %s %s\n",        //14
        "COM_NOT %s %s\n",          //15
        "COM_MARK %s\n",            //16
        "GOTOLABEL %s\n",           //17
        "GOTOLABEL_COND %s %s\n",   //18
        "COM_RETURN %s\n"           //19
    },
    {
        "   movl $%2$s, %1$s\n",
        "   movl %2$s, %%eax\n   movl %%eax, %1$s\n",
        "   movl $%s, %s\n",
        "   movl %s, %%eax\n   movl %%eax, %s\n",
        "   movl %1$s, %%eax\n   negl %%eax\n   movl %%eax, %2$s\n",
        "   movl %1$s, %%eax\n   addl %2$s, %%eax\n   movl %%eax, %3$s\n",
        "   movl %1$s, %%eax\n   movl %2$s, %%edx\n   subl %%edx, %%eax\n   movl %%eax, %3$s\n",
        "   movl %1$s, %%eax\n   imull %2$s, %%eax\n   movl %%eax, %3$s\n",
        "   movl %1$s, %%eax\n   sarl $31, %%edx\n   idivl %2$s\n   movl %%eax, %3$s\n",
        "   movl %1$s, %%edx\n   movl %%edx, %%eax\n   sarl $31, %%edx\n   idivl %2$s\n   movl %%edx, %3$s\n",
        "   movl %2$s, %%eax\n   cmpl %%eax, %1$s\n   setg %%al\n   movzbl %%al, %%eax\n   movl %%eax, %3$s\n",
        "   movl %2$s, %%eax\n   cmpl %%eax, %1$s\n   setl %%al\n   movzbl %%al, %%eax\n   movl %%eax, %3$s\n",
        "   movl %2$s, %%eax\n   cmpl %%eax, %1$s\n   sete %%al\n   movzbl %%al, %%eax\n   movl %%eax, %3$s\n",
        "   movl %1$s, %%eax\n   cmpl $0, %%eax\n   je %4$s\n   movl %2$s, %%eax\n   cmpl $0, %%eax\n   je %4$s\n   movl $1, %3$s\n   jmp %5$s\n%4$s:\n   movl $0, %3$s\n%5$s:\n",
        "   movl %1$s, %%eax\n   cmpl $0, %%eax\n   jne %4$s\n   movl %2$s, %%eax\n   cmpl $0, %%eax\n   jne %4$s\n   movl %2$s, %%eax\n   cmpl $0, %%eax\n   jne %4$s\n   movl $0, %3$s\n   jmp %5$s\n%4$s:\n   movl $1, %3$s\n%5$s:\n",
        "   movl %1$s, %%eax\n   cmpl $0, %%eax\n   je %3$s\n   movl $0, %2$s\n   jmp %4$s\n%3$s:\n   movl $1, %2$s\n%4$s:\n",
        "%s:\n",
        "   jmp %s\n",
        "   movl %1$s, %%eax\n   cmpl $0, %%eax\n   jne %2$s\n",
        "   movl %1$s, %%eax\n   leave\n   ret\n", //19
        "   filds %1$s\n   fstps %2$s\n",
        "   flds %1$s\n   fistpl %2$s\n",
        "   flds $-1\n   flds %1$s\n   fmuls\n   fstps %2$s\n", //MINUS FLOAT
        "   flds %1$s\n   flds %2$s\n   faddp\n   fstps %3$s\n", //ADD FLOAT
        "   flds %2$s\n   flds %1$s\n   fsubp\n   fstps %3$s\n", //SUB FLOAT
        "   flds %1$s\n   flds %2$s\n   fmulp\n   fstps %3$s\n", //MULT FLOAT
        "   flds %2$s\n   flds %1$s\n   fdivp\n   fstps %3$s\n", //DIV FLOAT
        "   flds %1$s\n   flds %2$s\n   fucompp\n   fnstsw %%ax\n   andb $69,%%ah\n   movl %%ah %3$s\n", //GT FLOAT
        "   flds %1$s\n   flds %2$s\n   fucompp\n   fnstsw %%ax\n   andb $69,%%ah\n   cmpb $1,%%ah\n   movl %%ah %3$s\n", //LT FLOAT
        "   flds %1$s\n   flds %2$s\n   fucompp\n   fnstsw %%ax\n   andb $69,%%ah\n   cmpb $64,%%ah\n   movl %%ah %3$s\n", //EQ FLOAT.
        "   flds %1$s\n   leave\n   ret\n"
    }
};

#endif